package com.ymdd.library.pickerview.utils;

import android.view.View;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by jzxiang on 16/4/20.
 */
public class Utils {

    public static String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};

    public static boolean isTimeEquals(WheelCalendar calendar, int... params) {
        switch (params.length) {
            case 1:
                return calendar.year == params[0];
            case 2:
                return calendar.year == params[0] &&
                        calendar.month == params[1];
            case 3:
                return calendar.year == params[0] &&
                        calendar.month == params[1] &&
                        calendar.day == params[2];
            case 4:
                return calendar.year == params[0] &&
                        calendar.month == params[1] &&
                        calendar.day == params[2] &&
                        calendar.hour == params[3];
        }
        return false;
    }

    public static void hideViews(View... views) {
        for (int i = 0; i < views.length; i++) {
            views[i].setVisibility(View.GONE);
        }
    }

    /**
     * 获取日期显示文字
     */
    public static String getDayText(Date date1, int page) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date1);
        cal.add(Calendar.DATE, page);//日

        int month = cal.get(Calendar.MONTH) + 1;//月（必须要+1）
        int day = cal.get(Calendar.DATE);//日
        int week = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (week < 0)
            week = 0;
        return month+"月" + day+"日"+weekDays[week];
    }

    /**
     * 获取日期显示文字
     */
    public static Date getTimeText(Date date1, int page) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date1);
        cal.add(Calendar.DATE, page);//日
        return cal.getTime();
    }

    public static String trimSpecialString(String mResult) {
        if (!"".equals(mResult)) {
            if (mResult.contains("时")) {
                mResult = mResult.replaceAll("时", "");
            }
            if (mResult.contains("分")) {
                mResult = mResult.replaceAll("分", "");
            }
        }
        return mResult;
    }
}
